package com.example.springMVC.service.impl;

import com.example.springMVC.commons.ServiceException;
import com.example.springMVC.dao.BillMapper;
import com.example.springMVC.pojo.Bill;
import com.example.springMVC.pojo.User;
import com.example.springMVC.service.BillService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class BillServiceImol implements BillService {
    @Autowired
    BillMapper billMapper;
    @Override
    public PageInfo<Bill> billList(Integer currentPage, Integer proId, Integer isPayment, String proName) {
        Map<String, Object> param = new HashMap<>();
        param.put("proId",proId);
        param.put("isPayment",isPayment);
        param.put("proName", proName);
        PageHelper.offsetPage((currentPage - 1) * 10, 10, true);
        List<Bill> userList = billMapper.billList(param);
        PageInfo<Bill> info = new PageInfo<>(userList);
        return info;
    }

    @Override
    public boolean billAdd(Bill bill) throws ServiceException {
        if (StringUtils.isAllBlank(bill.getBillCode())
                ||
                StringUtils.isAnyBlank(bill.getProductName())
                ||
                StringUtils.isAnyBlank(bill.getProductUnit())
        ) {
            throw new ServiceException("输入不能为空");
        }
        billMapper.billAdd(bill);
        return true;
    }

    @Override
    public boolean deleteBill(Long billId) {
        return billMapper.deleteBill(billId);
    }

    @Override
    public Bill getUserById(long billId) {

        return billMapper.getUserById(billId);
    }

    @Override
    public boolean updateBillById(Bill bill) {

        return billMapper.updateBillById(bill);
    }
}
